Skip to content

allow replacing stale cache - #163

Closed
titusfortner wants to merge 2 commits into
bazel-contrib:mainfrom
titusfortner:replace_cache
Closed

allow replacing stale cache#163
titusfortner wants to merge 2 commits into
bazel-contrib:mainfrom
titusfortner:replace_cache

Conversation

@titusfortner

Copy link
Copy Markdown
Contributor

Adds a new config value that deletes cache with matching prefixes before saving cache (limited to current ref).
My use case is that we only save cache from one branch, so as soon as the cache is changed we'll never need the old one, and when we are doing a lot of version bumps we're getting a lot of cache churn.

Requires actions: write permission on the workflow token. Requires cache-save: true (the default)

Separate note, if you wanted to make this work for #18 we could add a one line replacement:

  if (cacheHit === 'true') {

with

  if (cacheHit === 'true' && config.cacheReplace !== true) {

But I figured that was out of scope for my needs here.

Comment thread post.js Outdated
}

async function deleteCachesByPrefix(prefix) {
const token = process.env.BAZELISK_GITHUB_TOKEN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to use Bazelisk env var here. Let's thread token from token input to this post action via a state variable.

@p0deje p0deje left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your use-case is only about disk cache, right? I can see this being problematic for the repository and external caches because they are generally shared across multiple refs and are more stable. If my assumption is correct, let's change to disk-cache-replace instead.

Comment thread post.js

if (config.cacheReplace) {
const prefix = `${config.baseCacheKey}-${cacheConfig.name}-`
await deleteCachesByPrefix(prefix)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a problem for matrix jobs - each job that runs in parallel is going to delete the other job's caches and upload them instead.

@titusfortner

Copy link
Copy Markdown
Contributor Author

The use case I had in mind for this no longer applies, so I'm going to close it, but you (or anyone) is free to use/apply the code for future PRs or updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants